﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GM.Forms
{
    public partial class MaterialForm : Form
    {
        private MaterialMovementForm movementform = new MaterialMovementForm();

        public MaterialForm()
        {
            InitializeComponent();
        }

        private void MaterialForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            Hide();
        }

        private void gm_materialyBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.gm_materialyBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.evolutionDataSetmaterialy);

        }

        private void MaterialForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'evolutionDataSetmaterialy.gm_materialy' table. You can move, or remove it, as needed.
            this.gm_materialyTableAdapter.Fill(this.evolutionDataSetmaterialy.gm_materialy);

        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
          
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            movementform.setType(0);
            movementform.Show();
        }

        private void gm_materialyDataGridView_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            this.Validate();
            
            gm_materialyBindingSource.EndEdit();
            gm_materialyTableAdapter.Update(evolutionDataSetmaterialy.gm_materialy);
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            movementform.setType(1);
            movementform.Show();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            movementform.setType(2);
            movementform.Show();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            gm_materialyTableAdapter.Fill(evolutionDataSetmaterialy.gm_materialy);
            gm_materialyBindingSource.ResetBindings(false);
        }

        private void gm_materialyDataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if(e.ColumnIndex==3 || e.ColumnIndex==4)
            {
                int r;
                //string val = ((DataGridView)sender).Rows[e.RowIndex].Cells[e.ColumnIndex] .Value.ToString();
                string val = e.FormattedValue.ToString();
                if (!int.TryParse(val, out r))
                    e.Cancel = true;
            }
        }

        private void gm_materialyDataGridView_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            MessageBox.Show("");
        }
    }
}
